<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'资源添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layer,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-offset-1 col-sm-10" style="margin-left: -10px;width: 100%;">
                <button type="button" class="return-btn btn btn-w-m btn-primary">返回</button>
                <div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;margin-top: 10px;" ></div>
            </div>
        </div>
    </div>
</div>
<!-- START 内容部分 -->
<div class="container" >
    <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
        <input type="hidden" name="id" id="id" value="${createPlan.id}">
        <input type="hidden" name="createId" id="createId" value="${createPlan.createId}">
        <div class="form-group">
            <label class="control-label col-sm-2">实际装柜时间</label>
            <div class="col-sm-6">
                <input type="text" id="despatchDate" name="despatchDate" value="${createPlan.despatchDate}" placeholder="请选择开始时间" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">出运港</label>
            <div class="col-sm-6">
                <select name="despatchPort" id="despatchPort" class="form-control">
                    <option value="">请选择</option>
                    <%for(var p in port){%>
                    <option value="${p.id}" <%if(p.id == createPlan.despatchPort){print("selected");}%>  >${p.portName}</option>
                    <%}%>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">目的港</label>
            <div class="col-sm-6">
                <select id="despatchDest" name="despatchDest" class="form-control">
                    <option value="">请选择</option>
                    <%for(var p in port){%>
                    <option value="${p.id}"  <%if(p.id == createPlan.despatchDest){print("selected");}%> >${p.portName}</option>
                    <%}%>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">目的港仓库</label>
            <div class="col-sm-6">
                <select id="despatchStore" name="despatchStore" class="form-control">
                    <option value="">请选择</option>
                    <%if(null !=ware){%>
                        <%for(var p in ware){%>
                            <option value="${p.id}"  <%if(p.id == createPlan.despatchStore){print("selected");}%> >${p.portName}</option>
                        <%}%>
                    <%}%>
                </select>
            </div>
        </div>
        <%if(createPlan.despatchFreight !=null){%>
            <div class="form-group">
                <label class="control-label col-sm-2">运费</label>
                <div class="col-sm-6">
                    <input type="text" id="despatchFreight" name="despatchFreight" value="${createPlan.despatchFreight}"  class="form-control">
                </div>
            </div>
        <%}%>
        <div class="form-group">
            <label class="control-label col-sm-2">是否龙舟</label>
            <div class="col-sm-6">
                <select id="createSkuId" name="createSkuId" class="form-control">
                    <option value="">请选择</option>
                    <option value="是" <%if(null!= createPlan.createSkuId && '是' == createPlan.createSkuId){print("selected");}%>>是</option>
                    <option value="否" <%if(null == createPlan.createSkuId || '否'== createPlan.createSkuId){print("selected");}%>>否</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">会计期间</label>
            <div class="col-sm-6">
                <input type="text" id="createPeriod" name="createPeriod" value="${createPlan.createPeriod}" placeholder="请选择会计期间" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">货代公司</label>
            <div class="col-sm-6">
                <select id="despatchSupplier"  name="despatchSupplier"  class="form-control" xm-select="despatchSupplier" xm-select-radio xm-select-search>
                    <option value="">请选择</option>
                    <%for(var dict in supplier){%>
                    <option value="${dict.supplierName}" <%if(createPlan.despatchSupplier == dict.supplierName){print("selected");}%> >${dict.supplierName}</option>
                    <%}%>
                </select>
                <input type="hidden" id="createPlanPlace"value="${createPlan.createPlanPlace}" name="createPlanPlace">
            </div>
        </div>

        <input type="hidden" name="createPlanVolume" value="${createPlan.createPlanVolume}">
        <input type="hidden" name="createWeightTotal" value="${createPlan.createWeightTotal}">
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </div>
    </form>
</div>
<!-- END 内容部分 -->

<!-- START 公共脚本 -->
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,chosen,chosen-demo'}){}%>
<!-- END 公共脚本 -->
<script>
    laydate.render({
        elem: '#despatchDate',
        type: 'date',
        format: 'yyyy-MM-dd'
        ,trigger: 'click'
    });
    laydate.render({
        elem: '#createPeriod',
        type: 'month'
        ,trigger: 'click'
    });
    var cvalidator;
    $(function(){

        //初始化验证器
        cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));
        //提交表单
        $('.save-btn').on('click',function(){

            var despatchDate=$("#despatchDate").val();
            if(despatchDate==''){
                parent.layer.msg('请选择实际装柜日期！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var despatchPort=$("#despatchPort").val();
            if(despatchPort==''){
                parent.layer.msg('请选择出运港！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var despatchDest=$("#despatchDest").val();
            if(despatchDest==''){
                parent.layer.msg('请选择目的港！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var createPeriod=$("#createPeriod").val();
            if(createPeriod==''){
                parent.layer.msg('请选择会计期间！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }

            var index=layer.load();
            //数据提交
            $.post('/sea/physical/despatch/usave.do',$('#info-form').serialize(),function(data){
                if( data.ok ){
                    layer.close(index);
                    parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                        parent.$planTable.bootstrapTable('refresh');
                        parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
                    });
                }else{
                    layer.close(index);
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                }
            });
        });
        //返回
        $('.return-btn').on('click',function(){
            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
        });
    });

    $("#despatchDest").change(function () {
        var parentId=$("#despatchDest").val();
        getWare(parentId);
    });

    function getWare(parentId) {
        $.ajax({
            url:'/sea/physical/port/findByParenId',
            data:{
                id:parentId
            },
            type:'post',
            success:function (data) {
                var category='<option value="">全部分类</option>';
                $("#despatchStore").html(category);
                var list=data;
                if(list.length>0){
                    for(var i=0;i<list.length;i++){
                        category+='<option value="'+list[i].id+'">'+list[i].portName+'</option>';
                    }
                    $("#despatchStore").html(category);
                }
            }
        });
        //返回

    }
</script>
</body>
</html>